package com.neusoft.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class JdbcUtil {
	/**
	 * 获取数据库连接对象
	 * @return
	 */
	private Connection getConn() {
		Connection conn = null;
		try {
			InputStream is = this.getClass().getClassLoader().getResourceAsStream("database.properties");
			Properties prop = new Properties();
			prop.load(is);
			String url = prop.getProperty("url");
			String username = prop.getProperty("username");
			String password = prop.getProperty("password");
			conn = DriverManager.getConnection(url, username, password);
		} catch (Exception e) {
			System.out.println("获取数据库连接异常："+e.getMessage());
			e.printStackTrace();
		} 			
		return conn;
	}
	
	public ResultSet doQuery(String sql) {
		ResultSet rs = null;
		try {
			Statement st = getConn().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_UPDATABLE);
			rs = st.executeQuery(sql);
		} catch (SQLException e) {
			System.out.println("数据库查询操作异常：" + e.getMessage());
			e.printStackTrace();
		}
		
		return rs;
	}
	
	
	
}
